package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/10.
 */
@HttpInlet(Conn.INLET_GET_ABNORMAL_INFO)
public class GetAbnormalInfoList extends JTAsyGet<GetAbnormalInfoList.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String obdid = JTApplication.jtPreferences.readOdbID();

    public String type;

    public GetAbnormalInfoList(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);
    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray poList = body.optJSONArray("poList");

        if(poList.length()>0){

            for(int i = 0;i<poList.length();i++) {

                JSONObject abnormal_item = poList.optJSONObject(i);

                Abnormal mList = new Abnormal();

                mList.ID = abnormal_item.optString("orderId");

                mList.TITLE = abnormal_item.optString("title");

                mList.MESSAGE = abnormal_item.optString("message");

                mList.TIME = abnormal_item.optString("createTime");

                mList.KEY = abnormal_item.optString("MessageType");

                mList.LON = abnormal_item.optString("lon");

                mList.LAT = abnormal_item.optString("lat");

                mList.MESSAGEVALUE = abnormal_item.optString("MessageValue");

                mList.ADDRESS = abnormal_item.optString("address");

                mList.JPUSHMESSAGE = abnormal_item.optString("jPushMessage");

                mList.MESSAGELEVEL = abnormal_item.optString("message_level");

                info.AbnormalList.add(mList);

            }

        }

            return info;


    }

    public static class Info implements Serializable {

        public String msg;

        public List<Abnormal> AbnormalList = new ArrayList<>();

    }

    public static class Abnormal implements Serializable {

        public String ID, TITLE, MESSAGE, TIME, KEY,LON,LAT,MESSAGEVALUE,ADDRESS,JPUSHMESSAGE,MESSAGELEVEL;


    }


}
